import { http } from "@/utils/http";
import type { ResultProps } from "@/api/user";

export interface MaterialVerList {
  versionId: number;
  versionName: string;
  formulaCount: number;
  materialStatus: number;
  note: string;
  changeTime: Date;
  publishTime: Date;
}

export const getMaterialVerList = (data?: object) => {
  return http.requestJson<ResultProps<MaterialVerList[]>>(
    "post",
    "/material/version/getList",
    {
      data
    }
  );
};

export interface MaterialList {
  formulaId: string;
  formulaImg: string;
  formulaName: string;
  formulaTag: string;
  formulaStatus: number;
  note: string;
  publishTime: Date;
}

export const getMaterialList = (data?: object) => {
  return http.requestJson<ResultProps<MaterialList[]>>(
    "post",
    "/material/list/getList",
    {
      data
    }
  );
};

export interface CategoryProp {
  id: number;
  account_id: number;
  business_id: number;
  name: string;
  note: string;
  delete_status: 1 | 0;
  update_time: Date;
  create_time: Date;
}

export const getCategory = (data?: object) => {
  return http.requestJson<ResultProps<CategoryProp[]>>(
    "get",
    "/materialType/getMaterialTypeList",
    {
      data: {
        ...data,
        start_page: 0,
        size: 0
      }
    }
  );
};

export interface MaterialDetailProp {
  id: number;
  material_id: string;
  account_id: number;
  business_id: number;
  name: string;
  note: string;
  standard_amount: null;
  amount_unit: string;
  barcode: string;
  use_barcode: boolean;
  delete_status: number;
  publish_status: number;
  type_id: number | null;
  clean_time: number;
  overdue_time: number;
  cold_time: number | null;
  update_time: Date;
  create_time: Date;
  spec: null | string;
  material_config: string;
  type_name: null | string;
  index: null;
}

export interface MaterialOtherProp {
  type: string;
  fpMaterial: string;
  materialPrice: string;
  conversion: string;
  materialSource: "泡茶机" | "柜式机";
}

export const getMaterialDetList = (params?: object) => {
  return http.requestJson<ResultProps<MaterialDetailProp[]>>(
    "get",
    "/material/getMaterialAllList",
    {
      params
    }
  );
};

export interface ExpiryListProp {
  id: number;
  expiryId?: number;
  title: string;
  accountId: number;
  businessId: number;
  activeTime: null;
  isFront: null;
  expiryType: null;
  expiryTime: null;
  expiryAlert: boolean;
  storageMethod: null;
  personId: null;
  materialId: string;
  materialSource: string;
  startActiveTime: string;
  endActiveTime: string;
  isDefault: number;
  config: null;
}

export const expiryGetList = (data?: object) => {
  return http.requestJson<ResultProps<ExpiryListProp[]>>(
    "post",
    "/expiry/getList",
    {
      data
    }
  );
};

export const expiryAdd = (data?: object) => {
  return http.requestJson<ResultProps<null>>("post", "/expiry/add", {
    data
  });
};

export const expiryAddList = (data?: object) => {
  return http.requestJson<ResultProps<null>>("post", "/expiry/addList", {
    data
  });
};

export const expiryUpd = (data?: object) => {
  return http.requestJson<ResultProps<null>>("post", "/expiry/upd", {
    data
  });
};

export interface ExpiryDelProp {
  /**
   * 物料ID
   */
  materialId: string;
  /**
   * 物料来源
   */
  materialSource: string;

  [property: string]: any;
}

export const expiryDel = (data?: ExpiryDelProp) => {
  return http.requestJson<ResultProps<null>>("post", "/expiry/del", {
    data
  });
};

export interface ExpiryVersionDetailProp {
  /**
   * 版本名称
   */
  name?: string;
  /**
   * 版本描述
   */
  note?: string;
  /**
   * 上架状态：0->下架；1->上架
   */
  publishStatus?: number;

  [property: string]: any;
}

export const expiryVersionAdd = (data?: ExpiryVersionDetailProp) => {
  return http.requestJson<ResultProps<null>>("post", "/expiryVersion/add", {
    data
  });
};

export const expiryVersionUpd = (data?: ExpiryVersionDetailProp) => {
  return http.requestJson<ResultProps<null>>("post", "/expiryVersion/upd", {
    data
  });
};

export const expiryVersionDel = (data?: { ids: number[] }) => {
  return http.requestJson<ResultProps<null>>("post", "/expiryVersion/del", {
    data
  });
};

export interface ExpiryVersionProp {
  id: number;
  accountId: number;
  businessId: number;
  name: string;
  note: string;
  deleteStatus: number;
  publishStatus: number;
  publishTime: Date;
  updateTime: Date;
  createTime: Date;
}

export const expiryVersionGetList = (data?: object) => {
  return http.requestJson<ResultProps<ExpiryVersionProp[]>>(
    "post",
    "/expiryVersion/getList",
    {
      data
    }
  );
};

export const expiryVersionPublish = (data?: object) => {
  return http.requestJson<ResultProps<null>>("post", "/expiryVersion/publish", {
    data
  });
};

export const expiryVersionRelease = (data?: object) => {
  return http.requestJson<ResultProps<null>>("post", "/expiryVersion/release", {
    data
  });
};

export interface ExpiryVerReleaseProp {
  id: number;
  accountId: number;
  businessId: number;
  moduleKey: string;
  moduleId: string;
  groupId: null;
  storeId: null;
  deviceId: string;
  note: string;
  releaseTime: Date;
}

export const expiryVersionReleaseList = (data?: object) => {
  return http.requestJson<ResultProps<ExpiryVerReleaseProp[]>>(
    "post",
    "/expiryVersion/getReleaseList",
    {
      data
    }
  );
};

export interface MaterialMakeAddProp {
  /**
   * 物料制备图片url
   */
  formulaUrl?: string;
  /**
   * 物料制备视频url
   */
  makeUrl?: string;
  /**
   * 物料ID
   */
  materialId?: string;
  /**
   * 物料来源
   */
  materialSource?: string;
  /**
   * 制作名称
   */
  name?: string;
  /**
   * 制作步骤
   */
  stepList?: string;
  /**
   * 物料效期版本ID
   */
  versionId?: string;

  [property: string]: any;
}

export const materialMakeAdd = (data?: MaterialMakeAddProp) => {
  return http.requestJson<ResultProps<null>>("post", "/materialMake/add", {
    data
  });
};

export const materialMakeUpd = (
  data?: MaterialMakeAddProp & { id: string }
) => {
  return http.requestJson<ResultProps<null>>("post", "/materialMake/upd", {
    data
  });
};

export interface materialMakeProp {
  id: number;
  accountId: number;
  businessId: number;
  name: string;
  materialId: string;
  materialSource: string;
  versionId: string;
  formulaUrl: string;
  makeUrl: string;
  deleteStatus: number;
  updateTime: Date;
  createTime: Date;
  stepList: null;
}

export const materialMakeGetList = (data?: object) => {
  return http.requestJson<ResultProps<materialMakeProp[]>>(
    "post",
    "/materialMake/getList",
    {
      data
    }
  );
};

export const materialMakeDel = (data?: { ids: string[] }) => {
  return http.requestJson<ResultProps<null>>("post", "/materialMake/del", {
    data
  });
};
